<template>
  <div class="bg-white rounded-lg shadow p-4 lg:p-6">
    <div class="flex justify-between items-center mb-4">
      <h2 class="text-xl font-semibold text-gray-700">核心服务</h2>
      <button @click="addService" class="text-sm text-indigo-600 hover:text-indigo-800 flex items-center">
        添加服务
      </button>
    </div>

    <div class="space-y-4">
      <div v-for="(service, index) in modelValue" :key="service.id || index"
        class="border border-gray-200 rounded-lg p-4 hover:shadow-md transition-shadow">
        <div class="flex justify-between items-start mb-3">
          <div class="flex items-center">
            <input v-model="service.title" type="text" placeholder="服务标题"
              class="text-lg font-medium border-b border-transparent focus:border-gray-300 focus:outline-none">
          </div>
          <button @click="removeService(index)" class="text-red-500 hover:text-red-700">
            删除
          </button>
        </div>

        <textarea v-model="service.description" rows="2" placeholder="服务描述"
          class="w-full px-3 py-1 border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-indigo-500 mb-3"></textarea>

        <div class="grid grid-cols-1 lg:grid-cols-3 gap-3">
          <div>
            <label class="block text-xs text-gray-500 mb-1">图标名称</label>
            <input v-model="service.icon" type="text"
              class="w-full px-2 py-1 text-sm border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-indigo-500">
          </div>

          <div>
            <label class="block text-xs text-gray-500 mb-1">图标颜色</label>
            <input v-model="service.iconColor" type="text"
              class="w-full px-2 py-1 text-sm border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-indigo-500">
          </div>

          <div>
            <label class="block text-xs text-gray-500 mb-1">背景颜色</label>
            <input v-model="service.iconBg" type="text"
              class="w-full px-2 py-1 text-sm border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-indigo-500">
          </div>
          <!-- <div>
            <label class="block text-xs text-gray-500 mb-1">图片</label>
            <input v-model="service?.image" type="text"
              class="w-full px-2 py-1 text-sm border border-gray-200 rounded focus:outline-none focus:ring-1 focus:ring-indigo-500">
          </div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { Service } from '~/types/home';


const props = defineProps<{
  modelValue: Service[];
}>()

const emit = defineEmits(['update:modelValue'])

const addService = () => {
  const newServices = [...props.modelValue, {
    title: '',
    description: '',
    icon: '',
    iconColor: 'text-indigo-600',
    iconBg: 'bg-indigo-100',
  }]
  emit('update:modelValue', newServices)
}

const removeService = (index: number) => {
  const newServices = [...props.modelValue]
  newServices.splice(index, 1)
  emit('update:modelValue', newServices)
}
</script>